From 3e7324fa878ccc3147e32f112aaa40b124f21087 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Tue, 24 Jul 2007 08:51:26 +0000 Subject: [PATCH] Fix some valgrind warnings/errors. --- compegps.c | 1 + pathaway.c | 10 ++++------ pdbfile.c | 18 +++++++----------- pdbfile.h | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/compegps.c b/compegps.c index 0aa41ef40..a47400d8c 100644 --- a/compegps.c +++ b/compegps.c @@ -515,6 +515,7 @@ write_trkpt_cb(const waypoint *wpt) strftime(buff, sizeof(buff), "%d-%b-%y %H:%M:%S", &tm); strupper(buff); } + else strncpy(buff, "01-JAN-70 00:00:00", sizeof(buff)); gbfprintf(fout, "T A %.10f%c%c %.10f%c%c ", fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S', diff --git a/pathaway.c b/pathaway.c index b1461ea17..ee3705760 100644 --- a/pathaway.c +++ b/pathaway.c @@ -60,6 +60,7 @@ typedef struct ppdb_appdata } ppdb_appdata_t; #define PPDB_APPINFO_SIZE sizeof(struct ppdb_appdata) +static ppdb_appdata_t *appinfo; static char *opt_dbname = NULL; static char *opt_deficon = NULL; @@ -535,6 +536,7 @@ static void ppdb_wr_init(const char *fname) file_out = pdb_create(fname, MYNAME); mkshort_handle = mkshort_new_handle(); ct = 0; + appinfo = NULL; if (global_opts.synthesize_shortnames != 0) { @@ -561,6 +563,7 @@ static void ppdb_wr_deinit(void) str_pool_deinit(); xfree(fname_out); if (datefmt) xfree(datefmt); + if (appinfo) xfree(appinfo); } /* @@ -651,12 +654,10 @@ static void ppdb_write_wpt(const waypoint *wpt) static void ppdb_write(void) { - ppdb_appdata_t *appinfo = NULL; if (opt_dbname) strncpy(file_out->name, opt_dbname, PDB_DBNAMELEN); - file_out->name[PDB_DBNAMELEN-1] = 0; file_out->attr = PDB_FLAG_BACKUP; file_out->ctime = file_out->mtime = current_time() + 2082844800U; file_out->creator = PPDB_MAGIC; @@ -664,8 +665,7 @@ static void ppdb_write(void) if (global_opts.objective != wptdata) /* Waypoint target do not need appinfo block */ { - appinfo = xcalloc(PPDB_APPINFO_SIZE, 1); - + appinfo = xcalloc(1, sizeof(*appinfo)); file_out->appinfo = (void *)appinfo; file_out->appinfo_len = PPDB_APPINFO_SIZE; } @@ -693,8 +693,6 @@ static void ppdb_write(void) fatal(MYNAME ": Realtime positioning not supported.\n"); break; } - - if (appinfo != NULL) xfree(appinfo); } diff --git a/pdbfile.c b/pdbfile.c index d9a95a974..18f2c6173 100644 --- a/pdbfile.c +++ b/pdbfile.c @@ -72,9 +72,9 @@ pdb_load_data(pdbfile *fin) pdbrec_t *rec; /* load the header */ - fin->name = xcalloc(1, 32 + 1); - gbfread(fin->name, 1, 32, fin->file); - + gbfread(fin->name, 1, PDB_DBNAMELEN, fin->file); + fin->name[PDB_DBNAMELEN] = '\0'; + fin->attr = gbfgetuint16(fin->file); fin->version = gbfgetuint16(fin->file); fin->ctime = gbfgetuint32(fin->file); @@ -219,7 +219,6 @@ pdb_create(const char *filename, const char *module) pdbfile *res; res = xcalloc(1, sizeof(*res)); - res->name = xmalloc(PDB_DBNAMELEN + 1); strncpy(res->name, "Palm/OS Database", PDB_DBNAMELEN); res->file = gbfopen_be(filename, "wb", module);; res->mode = 2; @@ -305,9 +304,8 @@ pdb_flush(pdbfile *file) } len = strlen(file->name); - if (len > 32) len = 32; gbfwrite(file->name, 1, len, fout); - while (len++ < 32) gbfputc(0, fout); + while (len++ < PDB_DBNAMELEN) gbfputc(0, fout); gbfputuint16(file->attr, fout); gbfputuint16(file->version, fout); @@ -337,10 +335,9 @@ pdb_flush(pdbfile *file) gbfwrite(file->appinfo, 1, file->appinfo_len, fout); } - rec = file->rec_list; - while (rec) { - gbfwrite(rec->data, 1, rec->size, fout); - rec = rec->next; + for (rec = file->rec_list; rec; rec = rec->next) { + if (rec->size > 0) + gbfwrite(rec->data, 1, rec->size, fout); } } @@ -366,7 +363,6 @@ pdb_close(pdbfile *file) gbfclose(file->file); if ((file->mode & 1) && file->appinfo) xfree(file->appinfo); - xfree(file->name); rec = file->rec_list; while (rec) { diff --git a/pdbfile.h b/pdbfile.h index 4b2888976..bcfc4cac8 100644 --- a/pdbfile.h +++ b/pdbfile.h @@ -51,7 +51,7 @@ typedef struct pdbrec_s { typedef struct { gbfile *file; char mode; /* file-mode: 1 = read / 2 = write */ - char *name; /* database name */ + char name[PDB_DBNAMELEN + 1]; /* database name */ gbuint16 attr; /* attributes */ gbuint16 version; /* version */ time_t ctime; /* creation time */ -- 2.30.2